#include <stdio.h>
#include <stdlib.h>
#include "galois.h"
using namespace std;

main(int argc, char **argv)
{
  Galois *gc;
  unsigned int x, y, w;

  if (argc != 4) {
    fprintf(stderr, "usage: galois_mult x y w - does multiplication in GF(2^w)\n");
    exit(1);
  }

  sscanf(argv[1], "%u", &x);
  sscanf(argv[2], "%u", &y);
  w = atoi(argv[3]);

  if (w < 1 || w > 32) { fprintf(stderr, "Bad w\n"); exit(1); }

  if (w < 32 && x >= (1 << w)) { fprintf(stderr, "x must be in [0,%d]\n", (1 << w)-1); exit(1); }
  if (w < 32 && y >= (1 << w)) { fprintf(stderr, "y must be in [0,%d]\n", (1 << w)-1); exit(1); }

  gc = galois_init(w, -1);
  printf("%u\n", gc->galois_single_multiply(x, y));
  exit(0);
}
